home *** CD-ROM | disk | FTP | other *** search
/ Sprite 1984 - 1993 / Sprite 1984 - 1993.iso / src / machserver / 1.098 / fsrmt / fsrmtMigrate.c < prev    next >
C/C++ Source or Header  |  1991-01-08  |  7KB  |  205 lines

  1. /*
  2.  * fsRmtMigrate.c --
  3.  *
  4.  * Procedures to handle migrating open files between machines.  The basic
  5.  * strategy is to first do some local book-keeping on the client we are
  6.  * leaving, then ship state to the new client, then finally tell the
  7.  * I/O server about it, and finish up with local book-keeping on the
  8.  * new client.  There are three stream-type procedures used: 'migStart'
  9.  * does the initial book-keeping on the original client, 'migEnd' does
  10.  * the final book-keeping on the new client, and 'migrate' is called
  11.  * on the I/O server to shift around state associated with the client.
  12.  *
  13.  * Copyright (C) 1985, 1988, 1989 Regents of the University of California
  14.  * Permission to use, copy, modify, and distribute this
  15.  * software and its documentation for any purpose and without
  16.  * fee is hereby granted, provided that the above copyright
  17.  * notice appear in all copies.  The University of California
  18.  * makes no representations about the suitability of this
  19.  * software for any purpose.  It is provided "as is" without
  20.  * express or implied warranty.
  21.  */
  22.  
  23. #ifndef lint
  24. static char rcsid[] = "$Header: /sprite/src/kernel/fsrmt/RCS/fsrmtMigrate.c,v 9.2 90/12/06 21:56:11 jhh Exp Locker: mgbaker $ SPRITE (Berkeley)";
  25. #endif not lint
  26.  
  27.  
  28. #include <sprite.h>
  29. #include <fs.h>
  30. #include <fsutil.h>
  31. #include <fsconsist.h>
  32. #include <fsrmtMigrate.h>
  33. #include <fsio.h>
  34. #include <fspdev.h>
  35. #include <fsprefix.h>
  36. #include <fsNameOps.h>
  37. #include <byte.h>
  38. #include <rpc.h>
  39. #include <procMigrate.h>
  40.  
  41. #include <stdio.h>
  42.  
  43. #ifdef SOSP91
  44. #include <sospRecord.h>
  45. #endif
  46.  
  47. extern Boolean fsio_MigDebug;
  48. #define DEBUG( format ) \
  49.     if (fsio_MigDebug) { printf format ; }
  50.  
  51.  
  52.  
  53. /*
  54.  *----------------------------------------------------------------------
  55.  *
  56.  * Fsrmt_NotifyOfMigration --
  57.  *
  58.  *    This invokes the stream-specific migration routine on the I/O server.
  59.  *    This is used by various RMT (remote) stream types.
  60.  *
  61.  * Results:
  62.  *    A return status, plus new flags containing FS_RMT_SHARED bit,
  63.  *    a new stream offset, plus some stream-type-specific data used
  64.  *    when creating the I/O handle in the migEnd procedure.
  65.  *
  66.  * Side effects:
  67.  *      None here, but bookkeeping is done at the I/O server.
  68.  *    
  69.  *----------------------------------------------------------------------
  70.  */
  71. ReturnStatus
  72. Fsrmt_NotifyOfMigration(migInfoPtr, flagsPtr, offsetPtr, outSize, outData)
  73.     Fsio_MigInfo    *migInfoPtr;    /* Encapsulated information */
  74.     int        *flagsPtr;    /* New flags, may have FS_RMT_SHARED bit set */
  75.     int        *offsetPtr;    /* New stream offset */
  76.     int        outSize;    /* Size of returned data, outData */
  77.     Address    outData;    /* Returned data from server */
  78. {
  79.     register ReturnStatus    status;
  80.     Rpc_Storage     storage;
  81.     FsrmtMigParam        migParam;
  82.  
  83.     storage.requestParamPtr = (Address) migInfoPtr;
  84.     storage.requestParamSize = sizeof(Fsio_MigInfo);
  85.     storage.requestDataPtr = (Address)NIL;
  86.     storage.requestDataSize = 0;
  87.  
  88.     storage.replyParamPtr = (Address)&migParam;
  89.     storage.replyParamSize = sizeof(FsrmtMigParam);
  90.     storage.replyDataPtr = (Address) NIL;
  91.     storage.replyDataSize = 0;
  92.  
  93.     status = Rpc_Call(migInfoPtr->ioFileID.serverID, RPC_FS_MIGRATE, &storage);
  94.  
  95.     if (status == SUCCESS) {
  96.     FsrmtMigrateReply    *migReplyPtr;
  97.  
  98.     migReplyPtr = &(migParam.migReply);
  99.     *flagsPtr = migReplyPtr->flags;
  100.     *offsetPtr = migReplyPtr->offset;
  101.     if (migParam.dataSize > 0) {
  102.         if (outSize < migParam.dataSize) {
  103.         panic("Fsrmt_NotifyOfMigration: too much data returned %d not %d\n",
  104.               migParam.dataSize, outSize);
  105.         status = FAILURE;
  106.         } else {
  107.         bcopy((Address)&migParam.data, outData, migParam.dataSize);
  108.         }
  109.     }
  110.     } else if (fsio_MigDebug) {
  111.     printf("Fsrmt_NotifyOfMigration: status %x from remote migrate routine.\n",
  112.           status);
  113.     }
  114.     return(status);
  115. }
  116.  
  117. /*
  118.  *----------------------------------------------------------------------
  119.  *
  120.  * Fsrmt_RpcMigrateStream --
  121.  *
  122.  *    The RPC service stub for Fsrmt_NotifyOfMigration.
  123.  *    This invokes the Migrate routine for the I/O handle given in
  124.  *    the encapsulated stream state.
  125.  *
  126.  * Results:
  127.  *    FS_STALE_HANDLE if handle that if client that is migrating the file
  128.  *    doesn't have the file opened on this machine.  Otherwise return
  129.  *    SUCCESS.
  130.  *
  131.  * Side effects:
  132.  *    None.
  133.  *
  134.  *----------------------------------------------------------------------
  135.  */
  136. /*ARGSUSED*/
  137. ReturnStatus
  138. Fsrmt_RpcMigrateStream(srvToken, clientID, command, storagePtr)
  139.     ClientData srvToken;    /* Handle on server process passed to
  140.                  * Rpc_Reply */
  141.     int clientID;        /* Sprite ID of client host */
  142.     int command;        /* Command identifier */
  143.     Rpc_Storage *storagePtr;    /* The request fields refer to the request
  144.                  * buffers and also indicate the exact amount
  145.                  * of data in the request buffers.  The reply
  146.                  * fields are initialized to NIL for the
  147.                  * pointers and 0 for the lengths.  This can
  148.                  * be passed to Rpc_Reply */
  149. {
  150.     register Fsio_MigInfo        *migInfoPtr;
  151.     register Fs_HandleHeader    *hdrPtr;
  152.     register ReturnStatus    status;
  153.     register FsrmtMigrateReply    *migReplyPtr;
  154.     register FsrmtMigParam        *migParamPtr;
  155.     register Rpc_ReplyMem    *replyMemPtr;
  156.     Address                dataPtr;
  157.     int                dataSize;
  158.  
  159.     migInfoPtr = (Fsio_MigInfo *) storagePtr->requestParamPtr;
  160.  
  161.     hdrPtr = (*fsio_StreamOpTable[migInfoPtr->ioFileID.type].clientVerify)
  162.         (&migInfoPtr->ioFileID, migInfoPtr->srcClientID, (int *)NIL);
  163.     if (hdrPtr == (Fs_HandleHeader *) NIL) {
  164.     printf("Fsrmt_RpcMigrateStream, unknown %s handle <%d,%d>\n",
  165.         Fsutil_FileTypeToString(migInfoPtr->ioFileID.type),
  166.         migInfoPtr->ioFileID.major, migInfoPtr->ioFileID.minor);
  167.     return(FS_STALE_HANDLE);
  168.     }
  169.     Fsutil_HandleUnlock(hdrPtr);
  170.     migParamPtr = mnew(FsrmtMigParam);
  171.     migReplyPtr = &(migParamPtr->migReply);
  172.     migReplyPtr->flags = migInfoPtr->flags;
  173.     storagePtr->replyParamPtr = (Address)migParamPtr;
  174.     storagePtr->replyParamSize = sizeof(FsrmtMigParam);
  175.     storagePtr->replyDataPtr = (Address)NIL;
  176.     storagePtr->replyDataSize = 0;
  177.     status = (*fsio_StreamOpTable[hdrPtr->fileID.type].migrate) (migInfoPtr,
  178.         clientID, &migReplyPtr->flags, &migReplyPtr->offset,
  179.         &dataSize, &dataPtr);
  180.     migParamPtr->dataSize = dataSize;
  181.     if ((status == SUCCESS) && (dataSize > 0)) {
  182.     if (dataSize <= sizeof(migParamPtr->data)) {
  183.         bcopy(dataPtr, (Address) &migParamPtr->data, dataSize);
  184.         free(dataPtr);
  185.     } else {
  186.         panic("Fsrmt_RpcMigrateStream: migrate returned oversized buffer.\n");
  187.         return(FAILURE);
  188.     }
  189.     } 
  190. #ifdef SOSP91
  191.     {
  192.     SOSP_ADD_MIGRATE_TRACE(migInfoPtr->srcClientID, clientID,
  193.         migInfoPtr->streamID, migInfoPtr->offset);
  194.     }
  195. #endif
  196.     Fsutil_HandleRelease(hdrPtr, FALSE);
  197.  
  198.     replyMemPtr = (Rpc_ReplyMem *) malloc(sizeof(Rpc_ReplyMem));
  199.     replyMemPtr->paramPtr = storagePtr->replyParamPtr;
  200.     replyMemPtr->dataPtr = (Address) NIL;
  201.     Rpc_Reply(srvToken, status, storagePtr, Rpc_FreeMem,
  202.         (ClientData)replyMemPtr);
  203.     return(SUCCESS);
  204. }
  205.